package com.month.ai.advisors;

import com.month.ai.service.AiInteractionLogService;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.messages.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


import java.util.List;

/**
 * 自定义会话持久化存储方式
 */
@Component
public class DatabaseChatMemory implements ChatMemory {


    @Autowired
    private AiInteractionLogService aiInteractionLogService;


    //会话存取到数据库中
    @Override
    public void add(String conversationId, List<Message> messages) {
       aiInteractionLogService.SaveMessages(conversationId, messages);
    }

    //会话获取
    @Override
    public List<Message> get(String conversationId, int lastN) {
      return aiInteractionLogService.getMessages(conversationId, lastN);
    }

    //会话清理
    @Override
    public void clear(String conversationId) {

    }

}
